package com.ht.shop.controller;

import cn.dsna.util.images.ValidateCode;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

@WebServlet("/code")
public class CodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ValidateCode validateCode = new ValidateCode(120,40,4,30);
        String code = validateCode.getCode();
        req.getSession().setAttribute("code",code);
        System.out.println("验证码是：" + code);
        BufferedImage buffImg = validateCode.getBuffImg();
        ImageIO.write(buffImg,"jpeg",resp.getOutputStream());

    }
}
